import 'dart:async';
import 'package:factoryside/api/api.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';

///模拟数据
class MockRequest {

  static Future<dynamic> get(String action, Map params) async {
    return MockRequest.mock(getJsonName(action), params);
  }

  static Future<dynamic> post(String action, Map params) async {
    return MockRequest.mock(getJsonName(action), params);
  }

  static Future<dynamic> mock(String action, Map params) async {
    var responseStr = await rootBundle.loadString('mock/$action.json');
    var responseJson = json.decode(responseStr);
    print(responseJson);
    return responseJson;
  }

  static Map<String, String> map = {
    Api.getMessage: 'new_msg',
    Api.getMsgTab: 'msg_tab',
    Api.readMsg: 'generalSubmission',
    Api.walletDetails: 'bill',
    Api.newWorkerGetOrderList: 'newWorkerGetOrderList',
    Api.distinguish: 'distinguish',
    Api.getFactoryProd: 'getFactoryProd',
    Api.getFactoryBrand: 'getFactoryBrand',
    Api.getProdCategory: 'getProdCategory',
    Api.getProdModel: 'getProdModel',
    Api.getProdSpecifications: 'getProdSpecifications',
    Api.getParts: 'getParts',
    Api.getFactoryAddress: 'getFactoryAddress',
  };

  static getJsonName(String action) {
    return map[action];
  }
}
